/*
* 该文件由工具生成，请勿更改
* 接口说明病人登记分诊
* 创建时间：2018/6/5 10:47:03
**/
using System;
using System.Collections.Generic;
using System.Linq;
using Pacs.Services.Soa;
using System.Text;
using System.Threading.Tasks;
namespace Pacs.Services.Server.DJ_BingRenDengJiFenZhen
{
     public partial  class DJ_BingRenDengJiFenZhen:ServiceBase
     {
          public DTOResponse<DJ_BingRenDengJiFenZhenResponseParam> Excute(DJ_BingRenDengJiFenZhenRequest request)
          {
            var time = DateTime.Now;
            var JiuZhen = request.Body.PatientVisitInfo;
            var studys = request.Body.StudyInfos;
            JiuZhen.DengJiShiJian = time;

            var Pvbl = new Pacs.BLL.YW_PatientVisitInfo();
            Pvbl.Add(JiuZhen);
            var stuBl = new Pacs.BLL.YX_StudyInfo();
            foreach (var item in studys)
            {
                item.YW_PatientVisitInfoID = JiuZhen.ID;
                stuBl.Add(item);
                var workbl = new Pacs.BLL.YW_PatientWaitList();
                var work = new Pacs.Model.YW_PatientWaitList();
                work.ID = GuidTool.GetGuidStr();
                work.BingRenXingZhi = JiuZhen.BingRenLeiXing;
                work.JiuZhenXinXiID = JiuZhen.ID;
                work.XingMing = JiuZhen.XingMing;
                work.XiTongGuanLianHao = JiuZhen.XiTongGuanLianHao;
                work.ZhenShiID = item.JianChaShiID;
                work.ZhenShiMing = item.JianChaShiMing;
                work.YiLiaoJiGouID = JiuZhen.JianChaJiGouID;
                var ss = workbl.GetModelList("PaiXu in (select MAX(PaiXu) from YW_PatientWaitList) and YiLiaoJiGouID=" + work.YiLiaoJiGouID + "");
                if (ss.Count > 0)
                {
                    work.PaiXu = ss.FirstOrDefault().PaiXu + 1;
                }
                else
                {
                    work.PaiXu = 0;
                }
                workbl.Add(work);
            }

            var para = new DJ_BingRenDengJiFenZhenResponseParam();
            para.IsSucceed = true;
            return new DTOResponse<DJ_BingRenDengJiFenZhenResponseParam>(para);
        }
      }
}
